<template>
  <el-aside :width="collapse ? '180px' : '68px'">
    <el-menu class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" :collapse="!collapse" :collapse-transition="false">
      <h3 v-show="collapse">后台管理</h3>
      <h3 v-show="!collapse">后台</h3>
      <el-menu-item :index="item.path" v-for="item in noChildren()" :key="item.path" @click="clickMenu(item)">
        <component class="icons" :is="item.icon"></component>
        <span>{{ item.label }}</span>
      </el-menu-item>
      <el-sub-menu :index="item.label" v-for="item in hasChildren()" :key="item.path">
        <template #title>
          <component class="icons" :is="item.icon"></component>
          <span>{{ item.label }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item :index="subItem.path" v-for="(subItem,subIndex) in item.children" :key="subIndex" @click="clickMenu(subItem)">
            <component class="icons" :is="item.icon"></component>
          <span>{{ subItem.label }}</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu></el-aside
  >
</template>

<script lang="ts" setup>
import { ElAside, ElMenu, ElMenuItem, ElIcon, ElSubMenu, ElMenuItemGroup } from 'element-plus'
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import store from '../store/Button'
import { useRouter } from 'vue-router'
const router = useRouter()
const { collapse } = storeToRefs(store())
const list = ref([
  {
    path: '/user/users',
    label: '用户管理',
    icon: 'user',
    url: 'UserManage/UserManage',
  },
  {
    path: '/auth/auths',
    label: '权限管理',
    icon: 'Key',
    url: 'UserManage/UserManage',
  },
  {
    label: '留言板管理',
    icon: 'ChatLineSquare',
    children: [
      {
        path: '/message/reply',
        label: '评论',
        icon: 'setting',
        url: 'Other/PageOne',
      },
      {
        path: '/message/mess',
        label: '留言',
        icon: 'setting',
        url: 'Other/PageTwo',
      },
    ],
  },
])
const clickMenu = (item) => {
  router.push({
    path: item.path,
  })
}
const ywss=ref(false)
ywss.value=!ywss
const noChildren = () => {
  return list.value.filter((item) => !item.children)
}
noChildren
const hasChildren = () => {
  return list.value.filter((item) => item.children)
}
hasChildren


</script>

<style scoped lang="scss">
.icons {
  width: 18px;
  height: 18px;
}
.el-menu {
  border-right: none;
  h3 {
    line-height: 48px;
    color: #fff;
    text-align: center;
  }
}
</style>
